package com.example.springdemo.aware;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.stereotype.Component;

/**
 * @Author：DijaH
 * @Date：2024/3/20 11:17
 * @Version：1.0.0
 * @Description：
 */
@Component
public class MyBeanFactoryAwareBean implements BeanFactoryAware {

    private BeanFactory beanFactory;

    //实现BeanFactoryAware接口的回调方法
    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        this.beanFactory = beanFactory;
    }

    //用于从BeanFactory中获取bean
    public Object getBean(String beanName){
        return beanFactory.getBean(beanName);
    }
}
